package com.example.myworkers.controller;

import com.example.myworkers.model.Goods;
import com.example.myworkers.model.Grant;
import com.example.myworkers.service.GrantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 编写者：门硕然
 */

@Api(tags = "Grant")
@RestController
@RequestMapping("/grant")
public class GrantController {

    @Autowired
    private GrantService grantService;

    @ApiOperation(value = "添加方法")
    @GetMapping("/addGrant")
    @CrossOrigin
    public int addGrant( Grant grant){
        System.out.println("进入添加信息接口");
        return grantService.insertGrant(grant);
    }

    @ApiOperation(value = "查询方法-单个")
    @GetMapping("/getOne")
    @CrossOrigin
    public Grant getGrant(int id){
        System.out.println("进入单条查询接口");
        Grant grant=grantService.selectGrant(id);
        System.out.println("返回的数据集合为"+grant.getReceiver());
        return grant;
    }


    @ApiOperation(value = "修改方法")
    @GetMapping("/editGrant")
    @CrossOrigin
    public int editGrant(Grant grant){
        System.out.println("进入修改接口");
        return grantService.updateGrant(grant);
    }

    @ApiOperation(value = "删除方法")
    @GetMapping("/deleteGrant")
    @CrossOrigin
    public int deleteGrant(int id){
        System.out.println("进入删除接口");
        int returnValue=0;
        if (id!=0){
            returnValue=grantService.deleteGrant(id);
        }
        return returnValue;
    }




}
